package com.yanqu.road.server.cmd.beauty;

import com.yanqu.road.entity.player.BeautySelfSelectPatronsPosition;
import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.beauty.BeautyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BeautyModule;
import com.yanqu.road.server.pb.BeautyPb;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = BeautyProto.BeautySelfSelectPatronsSaveReqMsg.class, respMsg = BeautyProto.BeautySelfSelectPatronsSaveRespMsg.class)
@Cmd(code = Protocol.S_BEAUTY_SELF_SELECT_PATRONS_SAVE, desc = "自选缘分门客-保存")
public class BeautySelfSelectPatronsSaveCmd extends AbstractCommand {

    private int beautyId;//美女ID
    private int patronsId;//门客ID
    private int position;//孔位ID

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BeautyProto.BeautySelfSelectPatronsSaveReqMsg reqMsg = BeautyProto.BeautySelfSelectPatronsSaveReqMsg.parseFrom(packet.getBytes());
        beautyId = reqMsg.getBeautyId();
        patronsId = reqMsg.getPatronsId();
        position = reqMsg.getPosition();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        BeautyProto.BeautySelfSelectPatronsSaveRespMsg.Builder respMsg = BeautyProto.BeautySelfSelectPatronsSaveRespMsg.newBuilder();
        try {
            BeautySelfSelectPatronsPosition patronsPosition = player.getModule(BeautyModule.class).saveSelfSelectPatrons(beautyId, patronsId, position);
            respMsg.setRet(0);
            respMsg.setPatronsPosition(BeautyPb.buildBeautySelfSelectPatronsTempMsg(patronsPosition));
        } catch (BusinessException e) {
            respMsg.setRet(e.getCode());
        }
        player.sendPacket(Protocol.U_BEAUTY_SELF_SELECT_PATRONS_SAVE, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
